package cn.stylefeng.guns.modular.basic.service.impl;

import cn.stylefeng.guns.base.pojo.node.ZTreeNode;
import cn.stylefeng.guns.base.pojo.page.LayuiPageFactory;
import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.modular.basic.entity.BasicType;
import cn.stylefeng.guns.modular.basic.mapper.BasicTypeGsMapper;
import cn.stylefeng.guns.modular.basic.mapper.BasicTypeMapper;
import cn.stylefeng.guns.modular.basic.model.params.BasicTypeParam;
import cn.stylefeng.guns.modular.basic.model.result.BasicCodeResult;
import cn.stylefeng.guns.modular.basic.model.result.BasicTypeResult;
import  cn.stylefeng.guns.modular.basic.service.BasicTypeService;
import cn.stylefeng.guns.sys.modular.system.model.params.SysCompanyParam;
import cn.stylefeng.guns.sys.modular.system.model.result.SysCompanyResult;
import cn.stylefeng.roses.core.util.ToolUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.List;

/**
 * <p>
 * 通用编码 服务实现类
 * </p>
 *
 * @author 
 * @since 2024-01-05
 */
@Service
public class BasicTypeServiceImpl extends ServiceImpl<BasicTypeMapper, BasicType> implements BasicTypeService {

    @Override
    public void add(BasicTypeParam param){
        BasicType entity = getEntity(param);
        this.save(entity);
    }

    @Override
    public void delete(BasicTypeParam param){
        this.removeById(getKey(param));
    }

    @Override
    public void update(BasicTypeParam param){
        BasicType oldEntity = getOldEntity(param);
        BasicType newEntity = getEntity(param);
        ToolUtil.copyProperties(newEntity, oldEntity);
        this.updateById(newEntity);
    }

    @Override
    public BasicTypeResult findBySpec(BasicTypeParam param){
        return null;
    }

    @Override
    public List<BasicTypeResult> findListBySpec(BasicTypeParam param){
        return null;
    }

    @Override
    public LayuiPageInfo findPageBySpec(BasicTypeParam param,String condition){
        Page pageContext = getPageContext();
        IPage page = this.baseMapper.customPageList(pageContext, param,condition);
        return LayuiPageFactory.createPageInfo(page);
    }

    private Serializable getKey(BasicTypeParam param){
        return param.getId();
    }

    private Page getPageContext() {
        return LayuiPageFactory.defaultPage();
    }

    private BasicType getOldEntity(BasicTypeParam param) {
        return this.getById(getKey(param));
    }

    private BasicType getEntity(BasicTypeParam param) {
        BasicType entity = new BasicType();
        ToolUtil.copyProperties(param, entity);
        return entity;
    }

    @Override
    public List<ZTreeNode> tree(BasicTypeParam basicTypeParam) {
        return this.baseMapper.tree(basicTypeParam);
    }

    @Override
    public List<BasicTypeResult> likePids(Integer id) {
        return this.baseMapper.likePids(id);
    }




}
